home *** CD-ROM | disk | FTP | other *** search
/ Precision Software Appli…tions Silver Collection 1 / Precision Software Applications Silver Collection Volume One (PSM) (1993).iso / demos / devel3.exe / POINTER.C < prev    next >
C/C++ Source or Header  |  1992-05-17  |  2KB  |  75 lines

  1. /* Abstract pointer routine */
  2.  
  3. /* Written by Bernie Roehl, February 1992 */
  4.  
  5. /* Copyright 1992 by Bernie Roehl.
  6.    May be freely used to write software for release into the public domain;
  7.    all commercial endeavours MUST contact Bernie Roehl and Dave Stampe
  8.    for permission to incorporate any part of this software into their
  9.    products!
  10.  */
  11.  
  12. /* The idea is that you have a pointing device with (up to) 6 degrees of
  13.    freedom and (at least) two buttons */
  14.  
  15. /* There will be one of these modules for each possible pointing device;
  16.    you link in the one you're using */
  17.  
  18. /* Eventually this should be a TSR, and you just call down to it (similar
  19.    to how a mouse driver works) */
  20.    
  21. /* This version reads the mouse; if the right-hand button is down,
  22.    vertical  motion gets mapped to forward/backward */
  23.  
  24. #include <stdio.h>
  25. #include <dos.h>
  26. #include "pointer.h"
  27.  
  28. pointer_init(int port, POINTER *pointer)
  29.     {
  30.     union REGS r;
  31.     int i;
  32.     pointer->port = port;
  33.     pointer->gesture = pointer->buttons = 0;
  34.     pointer->x = pointer->y = pointer->z = 0;
  35.     pointer->pan = pointer->tilt = pointer->roll = 0;
  36.     pointer->sx = pointer->sy = pointer->sz = 1;
  37.     for (i = 0; i < 16; ++i) pointer->flex[i] = 0;
  38.     r.x.ax = 0;
  39.     int86(0x33, &r, &r);
  40.     return r.x.ax;    
  41.     }
  42.  
  43. pointer_read(POINTER *pointer)
  44.     {
  45.     union REGS r;
  46.     unsigned oldbutt;
  47.     oldbutt = pointer->buttons;
  48.     r.x.ax = 3;  /* read button status */
  49.     int86(0x33, &r, &r);
  50.     pointer->buttons = r.x.bx;
  51.     r.x.ax = 11;  /* read motion counters */
  52.     int86(0x33, &r, &r);
  53.     pointer->x += ((int) r.x.cx) * pointer->sx;
  54.     if (pointer->buttons & 0x02)
  55.         pointer->z -= ((int) r.x.dx) * pointer->sy;
  56.     else
  57.         pointer->y -= ((int) r.x.dx) * pointer->sz;
  58.     pointer->buttons &= 0x01;
  59.     return r.x.dx | r.x.cx | (pointer->buttons ^ oldbutt);  /* return non-zero if changed */
  60.     }
  61.  
  62. void pointer_scale(POINTER *pointer, long sx, long sy, long sz)
  63.     {
  64.     pointer->sx = sx; pointer->sy = sy; pointer->sz = sz;
  65.     }
  66.  
  67. void pointer_move(POINTER *pointer, long x, long y, long z)
  68.     {
  69.     pointer->x = x;  pointer->y = y;  pointer->z = z;
  70.     }
  71.  
  72. void pointer_quit(POINTER *pointer)
  73.     {
  74.     }
  75.